/* Copyright (c) 2004-2024 peigen.info. All rights reserved. */

package info.peigen.hotpot.manage.core.manage.repository.mapper;

import info.peigen.hotpot.component.data.repository.beetlsql.mapper.AbstractBeetlSqlManageMapper;
import info.peigen.hotpot.manage.core.enums.UserStatus;
import info.peigen.hotpot.manage.core.repository.entity.UserEntity;
import org.beetl.sql.mapper.annotation.Select;
import org.beetl.sql.mapper.annotation.Sql;
import org.beetl.sql.mapper.annotation.Template;
import org.beetl.sql.mapper.annotation.Update;

import java.util.List;

/**
 * <b>(UserManageMapper)</b>
 * 管理后台 "用户" 数据库映射服务
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2024-08-05
 */
@SuppressWarnings("unused")
public interface UserManageMapper extends AbstractBeetlSqlManageMapper<UserEntity> {
    @Template("select * from user where id in ( #{join(ids)} )")
    @Select
    List<UserEntity> listByIds(List<String> ids);

    @Template("delete from user where id in ( #{join(ids)} )")
    @Update
    void deleteByIds(List<Integer> ids);


    // 唯一索引[user_id]
    @Sql("select * from user where user_id = ?")
    @Select
    UserEntity findByUserId(String userId);

    @Sql("select * from user where user_id = ? for update")
    @Select
    UserEntity lockByUserId(String userId);

    @Sql("delete from user where user_id = ?")
    @Update
    void deleteByUserId(String userId);

    // 唯一索引[login_name]
    @Sql("select * from user where login_name = ?")
    @Select
    UserEntity findByLoginName(String loginName);

    @Sql("select * from user where login_name = ? for update")
    @Select
    UserEntity lockByLoginName(String loginName);

    @Sql("delete from user where login_name = ?")
    @Update
    void deleteByLoginName(String loginName);

    // 索引[status]
    @Sql("select * from user where status = ?")
    @Select
    UserEntity findByStatus(UserStatus status);

    @Sql("delete from user where status = ?")
    @Update
    void deleteByStatus(UserStatus status);
}